package com.bwie.user.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.bwie.user.conf.OssUtils;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.user.entity.GoodsEntity;
import com.bwie.user.service.GoodsService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 这是一个商品表
 *
 * @author ÕÔË«Ò¶
 * @email 1535715783@qq.com
 * @date 2022-02-22 10:58:46
 */
@RestController
@RequestMapping("user/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private OssUtils ossUtils;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);

        return R.ok().put("page",page);
    }
    @RequestMapping("/goodsList")
    public R goodsList(){

        return goodsService.goodsList();
    }


    //图片上传
    @RequestMapping("/upload")
    public R upload(MultipartFile file){
        R r = ossUtils.uploadFile(file);

        return r;
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{goodsId}")
    public R info(@PathVariable("goodsId") Long goodsId){
		GoodsEntity goods = goodsService.getById(goodsId);

        return R.ok().put("goods", goods).setData(goods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] goodsIds){
		goodsService.removeByIds(Arrays.asList(goodsIds));
        return R.ok();
    }
}
